package com.thomasmoerman.dci2.frw

import javax.sql.DataSource

class C3P0DataSourceFactory(
  val dataSourceName: String,
  val user: String,
  val password: String,
  val driverClass: String,
  val jdbcUrl: String,
  val minPoolSize: Int = 1,
  val maxPoolSize: Int = 5) {

  import com.mchange.v2.c3p0.ComboPooledDataSource

  lazy val instance: DataSource = {
    val result = new ComboPooledDataSource

    result.setDataSourceName(dataSourceName)
    result.setUser(user)
    result.setPassword(password)
    result.setDriverClass(driverClass)
    result.setJdbcUrl(jdbcUrl)
    result.setMinPoolSize(minPoolSize)
    result.setMaxPoolSize(maxPoolSize)

    result
  }

}